package com.dhl.cloud.course.service;


import java.util.List;

import com.dhl.cloud.course.dao.LessionTransaudioMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.dhl.cloud.common.util.DateUtils;
import com.dhl.cloud.course.dao.LessionTranscriptmutMapper;
import com.dhl.cloud.course.dao.LessionTransfileMapper;
import com.dhl.cloud.course.entity.LessionTransfile;

@Service
public class LessionTransfileService {
	@Autowired
	private LessionTransfileMapper lessionTransfileMapper;
	@Autowired
	private LessionTranscriptmutMapper lessionTranscriptmutMapper;
	@Autowired
	private LessionTransaudioMapper lessionTransaudioMapper;

	public List<LessionTransfile> selectByLessionid(Integer lessionid) {
		List<LessionTransfile> list =  lessionTransfileMapper.selectByLessionid(lessionid);
		//LessionTransfile 设置翻译的段落
		for (LessionTransfile lsf:list)
		{
			lsf.setList(lessionTranscriptmutMapper.selectByLessionnum(lsf.getLessionnum()));
			//设置录音
			lsf.setLessionTransaudio(lessionTransaudioMapper.selectBylessionnum(lsf.getLessionnum()));
		}

		return list;
	}

	public int deleteByPrimaryKey(Integer id) {
		return lessionTransfileMapper.deleteByPrimaryKey(id);
	}

	public int insert(LessionTransfile c) {
		if (c.getId() != null)
		{
			LessionTransfile cc = lessionTransfileMapper.selectByPrimaryKey(c.getId());
			cc.setLessionnum(c.getLessionnum());
			cc.setFilename(c.getFilename());
			cc.setFilesize(c.getFilesize());
			cc.setFilepath(c.getFilepath());
			cc.setModifytime(DateUtils.getDateTime());
			return lessionTransfileMapper.updateByPrimaryKey(cc);
		}
		else
		{
			c.setCreatetime(DateUtils.getDateTime());
			return lessionTransfileMapper.insert(c);
		}

	}
}
